package lesson02;

public class Demo_203 {
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                System.out.println(Thread.currentThread().getName() + "  我还活着...");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println(Thread.currentThread().getName() + "   我即将死去");
        });

        System.out.println(thread.getName()
                + ": ID: " + thread.getId());
        System.out.println(thread.getName()
                + ": 名称: " + thread.getName());
        System.out.println(thread.getName()
                + ": 状态: " + thread.getState());
        System.out.println(thread.getName()
                + ": 优先级: " + thread.getPriority());
        System.out.println(thread.getName()
                + ": 后台线程: " + thread.isDaemon());
        System.out.println(thread.getName()
                + ": 活着: " + thread.isAlive());
        System.out.println(thread.getName()
                + ": 被中断: " + thread.isInterrupted());

        // 启动线程，申请真正的PCB，参与CPU调度
        thread.start();
        while (thread.isAlive()) {
//            System.out.println(Thread.currentThread().getName()
//                    + ": 状态: " + thread.getState());
        }
        System.out.println(thread.getName()
                + ": 状态: " + thread.getState());

    }
}
